import Mock from 'mockjs';
import { routerData } from './routerData';
import {
  orderData,
  orderData30,
  orderData90,
  vipData,
  vipData30,
  vipData90,
} from './finance';
import {
  echart1Y,
  echart1Y7,
  echart1Y30,
  echart2Y,
  echart2Y7,
  echart2Y30,
  echart3This,
  echart3Pre,
  Descriptions1Y,
  Descriptions1Y7,
  Descriptions1Y30,
  ShopEchart1Y,
  ShopEchart1Y7,
  ShopEchart1Y30,
  ShopTable1Y,
  ShopTable1Y7,
  ShopTable1Y30,
} from './statistics';

// 登录
Mock.mock('http://127.0.0.1:5000/api/login', 'post', (req) => {
  let data = JSON.parse(req.body);
  if (data.username === 'admin' && data.password === '111') {
    return Mock.mock({
      code: 200,
      msg: '登录成功',
      data: {
        token: 'dhawjoldw',
        userInfo: {
          userName: '张三',
        },
        routerData,
      },
    });
  }
  return Mock.mock({
    code: 203,
    msg: 'err',
  });
});

// 财务
//获取订单统计
Mock.mock('http://127.0.0.1:5000/home/finance/getOrder', 'post', (req) => {
  let data = JSON.parse(req.body);
  if (data === 'all') {
    return Mock.mock({
      code: 200,
      msg: '获取订单统计数据成功',
      data: {
        orderData,
      },
    });
  } else if (data === 'late30') {
    return Mock.mock({
      code: 200,
      msg: '获取订单统计数据成功',
      data: {
        orderData: orderData30,
      },
    });
  } else if (data === 'late90') {
    return Mock.mock({
      code: 200,
      msg: '获取订单统计数据成功',
      data: {
        orderData: orderData90,
      },
    });
  }
  return Mock.mock({
    code: 203,
    msg: 'err',
  });
});
//获取会员统计
Mock.mock('http://127.0.0.1:5000/home/finance/getVip', 'post', (req) => {
  let data = req.body;
  if (data === 'all') {
    return Mock.mock({
      code: 200,
      msg: '获取会员统计数据成功',
      data: {
        vipData,
      },
    });
  } else if (data === 'late30') {
    return Mock.mock({
      code: 200,
      msg: '获取会员统计数据成功',
      data: {
        vipData: vipData30,
      },
    });
  } else if (data === 'late90') {
    return Mock.mock({
      code: 200,
      msg: '获取会员统计数据成功',
      data: {
        vipData: vipData90,
      },
    });
  }
  return Mock.mock({
    code: 203,
    msg: 'err',
  });
});

// 获取统计中交易统计的echart数据
Mock.mock('http://127.0.0.1:5000/home/statistics/getEchart1', 'post', (req) => {
  let data = req.body;
  if (data === 'yesterday') {
    return Mock.mock({
      code: 200,
      msg: '获取统计echart数据成功',
      data: {
        echartData: echart1Y,
      },
    });
  } else if (data === 'late7') {
    return Mock.mock({
      code: 200,
      msg: '获取统计echart数据成功',
      data: {
        echartData: echart1Y7,
      },
    });
  } else if (data === 'late30') {
    return Mock.mock({
      code: 200,
      msg: '获取统计echart数据成功',
      data: {
        echartData: echart1Y30,
      },
    });
  }
  return Mock.mock({
    code: 203,
    msg: 'err',
  });
});

Mock.mock('http://127.0.0.1:5000/home/statistics/getEchart2', 'post', (req) => {
  let data = req.body;
  if (data === 'yesterday') {
    return Mock.mock({
      code: 200,
      msg: '获取统计echart数据成功',
      data: {
        echartData: echart2Y,
      },
    });
  } else if (data === 'late7') {
    return Mock.mock({
      code: 200,
      msg: '获取统计echart数据成功',
      data: {
        echartData: echart2Y7,
      },
    });
  } else if (data === 'late30') {
    return Mock.mock({
      code: 200,
      msg: '获取统计echart数据成功',
      data: {
        echartData: echart2Y30,
      },
    });
  }
  return Mock.mock({
    code: 203,
    msg: 'err',
  });
});

Mock.mock('http://127.0.0.1:5000/home/statistics/getEchart3', 'post', (req) => {
  let data = req.body;
  if (data === 'thisMouth') {
    return Mock.mock({
      code: 200,
      msg: '获取统计echart数据成功',
      data: {
        echartData: echart3This,
      },
    });
  } else if (data === 'preMouth') {
    return Mock.mock({
      code: 200,
      msg: '获取统计echart数据成功',
      data: {
        echartData: echart3Pre,
      },
    });
  }
  return Mock.mock({
    code: 203,
    msg: 'err',
  });
});

//获取统计中交易统计的Descriptions数据
Mock.mock(
  'http://127.0.0.1:5000/home/statistics/getDescriptions1',
  'post',
  (req) => {
    let data = req.body;
    if (data === 'yesterday') {
      return Mock.mock({
        code: 200,
        msg: '获取统计Descriptions数据成功',
        data: {
          DescriptionsData: Descriptions1Y,
        },
      });
    } else if (data === 'late7') {
      return Mock.mock({
        code: 200,
        msg: '获取统计Descriptions数据成功',
        data: {
          DescriptionsData: Descriptions1Y7,
        },
      });
    } else if (data === 'late30') {
      return Mock.mock({
        code: 200,
        msg: '获取统计Descriptions数据成功',
        data: {
          DescriptionsData: Descriptions1Y30,
        },
      });
    }
    return Mock.mock({
      code: 203,
      msg: 'err',
    });
  }
);

// 获取统计中商品统计的echart数据
Mock.mock(
  'http://127.0.0.1:5000/home/statistics/getShopEchart1',
  'post',
  (req) => {
    let data = req.body;
    if (data === 'yesterday') {
      return Mock.mock({
        code: 200,
        msg: '获取统计echart数据成功',
        data: {
          echartData: ShopEchart1Y,
        },
      });
    } else if (data === 'late7') {
      return Mock.mock({
        code: 200,
        msg: '获取统计echart数据成功',
        data: {
          echartData: ShopEchart1Y7,
        },
      });
    } else if (data === 'late30') {
      return Mock.mock({
        code: 200,
        msg: '获取统计echart数据成功',
        data: {
          echartData: ShopEchart1Y30,
        },
      });
    }
    return Mock.mock({
      code: 203,
      msg: 'err',
    });
  }
);

// 获取统计中商品统计的table数据
Mock.mock(
  'http://127.0.0.1:5000/home/statistics/getShopTable1',
  'post',
  (req) => {
    let data = req.body;
    if (data === 'yesterday') {
      return Mock.mock({
        code: 200,
        msg: '获取统计table数据成功',
        data: {
          tableData: ShopTable1Y,
        },
      });
    } else if (data === 'late7') {
      return Mock.mock({
        code: 200,
        msg: '获取统计table数据成功',
        data: {
          tableData: ShopTable1Y7,
        },
      });
    } else if (data === 'late30') {
      return Mock.mock({
        code: 200,
        msg: '获取统计table数据成功',
        data: {
          tableData: ShopTable1Y30,
        },
      });
    }
    return Mock.mock({
      code: 203,
      msg: 'err',
    });
  }
);

Mock.mock(
  'http://127.0.0.1:5000/home/statistics/getShopTable2',
  'post',
  (req) => {
    let data = req.body;
    if (data === 'yesterday') {
      return Mock.mock({
        code: 200,
        msg: '获取统计table数据成功',
        data: {
          tableData: ShopTable1Y,
        },
      });
    } else if (data === 'late7') {
      return Mock.mock({
        code: 200,
        msg: '获取统计table数据成功',
        data: {
          tableData: ShopTable1Y7,
        },
      });
    } else if (data === 'late30') {
      return Mock.mock({
        code: 200,
        msg: '获取统计table数据成功',
        data: {
          tableData: ShopTable1Y30,
        },
      });
    }
    return Mock.mock({
      code: 203,
      msg: 'err',
    });
  }
);
